<?php
//error_reporting(E_ERROR|E_PARSE);
//header("Content-Type:text/html; charset=utf-8");
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录');\r\n";
echo "location.href='../index.php'\r\n";
echo "</script>";
}else{
require_once('../config.php');
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
// function export_xls($filename,$table){
//     $exportString=$table;
 
//     header("Cache-Control:public");
//     header("Pragma:public");
//     header("Content-type: Content-type:application/vnd.ms-excel");
//     header("Accept-Ranges: bytes");
//     header("Content-Disposition:attachment; filename=".$filename);
//     header("Content-length:".strlen($exportString));
//     echo $exportString;
//     exit;
// }
function replacebd($str1,$str2){
 $s1=explode("Brand Name:",$str1);
 $s2=explode('&lt;br/&gt;',$s1[1]);
 $s3=str_replace($s2[0],$str2,$str1);
 return $s3;
}
function randomkeys($length)   
{   
   //$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ'; 
      $str = null;
      $strPol = "123456789";//大小写字母以及数字
      $max = strlen($strPol)-1;
      
      for($i=0;$i<$length;$i++){
         $str.=$strPol[rand(0,$max)];
      }
      return $str;
}
function EAN13($n){
        $n=(string)$n;
        $a=(($n[1]+$n[3]+$n[5]+$n[7]+$n[9]+$n[11])*3+$n[0]+$n[2]+$n[4]+$n[6]+$n[8]+$n[10])%10;
        $a=$a==0?0:10-$a;
        return $n.$a;
    }
$lang=$_GET["lang"];
$bname=$_GET["bname"];
$department_name=$_POST["department_name"];
$brand=$_POST["brand"];
$ProductType=$_POST["ProductType"];
$item_type=$_POST["item_type"];
//$manufacturer=$_POST["manufacturer"];
$user_name=$_SESSION["managername"];
if($_SESSION["thetype"]=="超级管理员"){$sql="select * from ph_".$lang." where 1=1";}
if($_SESSION["thetype"]=="管理员"){
$query="select admin from ph_admin where admin='".$_SESSION["managername"]."' or parent='".$_SESSION["managername"]."'";
$resulty=mysqli_query($conn,$query);
$array=array();
while($rowy = mysqli_fetch_array($resulty)){
array_push($array,"'".$rowy[admin]."'");
}
$alluser=implode(',', $array);
$sql="select * from ph_".$lang." where 1=1 and user_name in(".$alluser.")";}
if($_SESSION["thetype"]=="员工"){$sql="select * from ph_".$lang." where 1=1 and user_name='".$_SESSION["managername"]."'";}
if($bname!==''&&isset($bname)){$sql.=" and bname ='".$bname."'";}
$result=mysqli_query($conn,$sql);
$timeStart = microtime(true);
require_once("../PHP_XLSXWriter/vendor/autoload.php");
$writer = new XLSXWriter();
$filename = $bname."-".date('Ymdhis', time()).".xlsx";
header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$sheetHeader1 = [
    'TemplateType=fptcustom',
    'Version=2019.0110',
    'TemplateSignature=T1VURVJXRUFS',
    'The top 3 rows are for Amazon.com use only. Do not modify or delete the top 3 rows.',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    'Images',
    '',
    '',
    'Variation',
    '',
    '',
    '',
    'Basic',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    'Discovery',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    'Product Enrichment',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    'Dimensions',
    '',
    '',
    '',
    '',
    '',
    'Fulfillment',
    '',
    '',
    '',
    '',
    '',
    '',
    'Compliance',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    'Offer',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    'Additional Product Information',
    '',
    '',
    '',
    '',
    ''
  ];
  $sheetHeader2 = [
    'Product Type',
    'Seller SKU',
    'Brand Name',
    'Product Name',
    'Product ID',
    'Product ID Type',
    'Item Type Keyword',
    'Outer Material Type',
    'Outer Material Type',
    'Outer Material Type',
    'Outer Material Type',
    'Outer Material Type',
    'Color',
    'Color Map',
    'Size',
    'Department',
    'Size Map',
    'Standard Price',
    'Quantity',
    'Main Image URL',
    'Material Composition',
    'Material Composition',
    'Material Composition',
    'Material Composition',
    'Material Composition',
    'Material Composition',
    'Material Composition',
    'Material Composition',
    'Material Composition',
    'Material Composition',
    'Other Image URL',
    'Other Image URL',
    'Other Image URL',
    'Parentage',
    'Parent SKU',
    'Relationship Type',
    'Variation Theme',
    'Update Delete',
    'Product Description',
    'Closure Type',
    'Style Number',
    'Inner Material Type',
    'Inner Material Type',
    'Inner Material Type',
    'Inner Material Type',
    'Inner Material Type',
    'Manufacturer Part Number',
    'Manufacturer',
    'Key Product Features',
    'Key Product Features',
    'Key Product Features',
    'Key Product Features',
    'Key Product Features',
    'Key Product Features',
    'Search Terms',
    'Fit Type',
    'Country/Region as Labeled',
    'Sport Type',
    'theme',
    'top-style',
    'water-resistance-level',
    'fabric-wash',
    'Neck Size',
    'Neck Size Unit Of Measure',
    'NeckStyle',
    'SleeveLength',
    'Sleeve Length Unit Of Measure',
    'Sleeve Type',
    'Additional Features',
    'Additional Features',
    'Additional Features',
    'Additional Features',
    'Additional Features',
    'Style',
    'material_type',
    'Shipping Weight',
    'Website Shipping Weight Unit Of Measure',
    'Item Length',
    'Item Width',
    'Item Height',
    'Item Dimensions Unit Of Measure',
    'Fulfillment Center ID',
    'Package Height',
    'Package Width',
    'Package Length',
    'Package Weight',
    'Package Weight Unit Of Measure',
    'Package Dimensions Unit Of Measure',
    'Cpsia Warning',
    'CPSIA Warning Description',
    'Fabric Type',
    'Import Designation',
    'item_weight_unit_of_measure',
    'Item Weight',
    'Country/Region of Origin',
    'Is this product a battery or does it utilize batteries?',
    'Batteries are Included',
    'Battery composition',
    'Battery type/size',
    'Battery type/size',
    'Battery type/size',
    'Number of batteries',
    'Number of batteries',
    'Number of batteries',
    'Battery weight (grams)',
    'battery_weight_unit_of_measure',
    'Number of Lithium Metal Cells',
    'Number of Lithium-ion Cells',
    'Lithium Battery Packaging',
    'Watt hours per battery',
    'lithium_battery_energy_content_unit_of_measure',
    'Lithium content (grams)',
    'lithium_battery_weight_unit_of_measure',
    'Applicable Dangerous Goods Regulations',
    'Applicable Dangerous Goods Regulations',
    'Applicable Dangerous Goods Regulations',
    'Applicable Dangerous Goods Regulations',
    'Applicable Dangerous Goods Regulations',
    'UN number',
    'Safety Data Sheet (SDS) URL',
    'Volume',
    'item_volume_unit_of_measure',
    'Flash point (°C)?',
    'Categorization/GHS pictograms (select all that apply)',
    'Categorization/GHS pictograms (select all that apply)',
    'Categorization/GHS pictograms (select all that apply)',
    'California Proposition 65 Warning Type',
    'California Proposition 65 Chemical Names',
    'Additional Chemical Name1',
    'Additional Chemical Name2',
    'Additional Chemical Name3',
    'Additional Chemical Name4',
    'Manufacturer\'s Suggested Retail Price',
    'Product Tax Code',
    'Handling Time',
    'Launch Date',
    'Release Date',
    'Restock Date',
    'Sale Price',
    'Sale Start Date',
    'Sale End Date',
    'Stop Selling Date',
    'Max Aggregate Ship Quantity',
    'Package Quantity',
    'Number of Items',
    'Offering Can Be Gift Messaged',
    'Is Gift Wrap Available',
    'Is Discontinued by Manufacturer',
    'Max Order Quantity',
    '>Shipping-Template',
    'Offering Release Date',
    'Bottom Style',
    'Collar Type',
    'Control Type',
    'pattern-style',
    'pocket-description',
    'Special Size Type'
   ];
  $sheetHeader3 = [
    'feed_product_type',
    'item_sku',
    'brand_name',
    'item_name',
    'external_product_id',
    'external_product_id_type',
    'item_type',
    'outer_material_type1',
    'outer_material_type2',
    'outer_material_type3',
    'outer_material_type4',
    'outer_material_type5',
    'color_name',
    'color_map',
    'size_name',
    'department_name',
    'size_map',
    'standard_price',
    'quantity',
    'main_image_url',
    'material_composition1',
    'material_composition2',
    'material_composition3',
    'material_composition4',
    'material_composition5',
    'material_composition6',
    'material_composition7',
    'material_composition8',
    'material_composition9',
    'material_composition10',
    'other_image_url1',
    'other_image_url2',
    'other_image_url3',
    'parent_child',
    'parent_sku',
    'relationship_type',
    'variation_theme',
    'update_delete',
    'product_description',
    'closure_type',
    'model',
    'inner_material_type1',
    'inner_material_type2',
    'inner_material_type3',
    'inner_material_type4',
    'inner_material_type5',
    'part_number',
    'manufacturer',
    'bullet_point1',
    'bullet_point2',
    'bullet_point3',
    'bullet_point4',
    'bullet_point5',
    'bullet_point6',
    'generic_keywords',
    'fit_type',
    'country_as_labeled',
    'sport_type',
    'theme',
    'top_style',
    'water_resistance_level',
    'fabric_wash',
    'neck_size',
    'neck_size_unit_of_measure',
    'neck_style',
    'sleeve_length',
    'sleeve_length_unit_of_measure',
    'sleeve_type',
    'special_features1',
    'special_features2',
    'special_features3',
    'special_features4',
    'special_features5',
    'style_name',
    'material_type',
    'website_shipping_weight',
    'website_shipping_weight_unit_of_measure',
    'item_length',
    'item_width',
    'item_height',
    'item_dimensions_unit_of_measure',
    'fulfillment_center_id',
    'package_height',
    'package_width',
    'package_length',
    'package_weight',
    'package_weight_unit_of_measure',
    'package_dimensions_unit_of_measure',
    'cpsia_cautionary_statement',
    'cpsia_cautionary_description',
    'fabric_type',
    'import_designation',
    'item_weight_unit_of_measure',
    'item_weight',
    'country_of_origin',
    'batteries_required',
    'are_batteries_included',
    'battery_cell_composition',
    'battery_type1',
    'battery_type2',
    'battery_type3',
    'number_of_batteries1',
    'number_of_batteries2',
    'number_of_batteries3',
    'battery_weight',
    'battery_weight_unit_of_measure',
    'number_of_lithium_metal_cells',
    'number_of_lithium_ion_cells',
    'lithium_battery_packaging',
    'lithium_battery_energy_content',
    'lithium_battery_energy_content_unit_of_measure',
    'lithium_battery_weight',
    'lithium_battery_weight_unit_of_measure',
    'supplier_declared_dg_hz_regulation1',
    'supplier_declared_dg_hz_regulation2',
    'supplier_declared_dg_hz_regulation3',
    'supplier_declared_dg_hz_regulation4',
    'supplier_declared_dg_hz_regulation5',
    'hazmat_united_nations_regulatory_id',
    'safety_data_sheet_url',
    'item_volume',
    'item_volume_unit_of_measure',
    'flash_point',
    'ghs_classification_class1',
    'ghs_classification_class2',
    'ghs_classification_class3',
    'california_proposition_65_compliance_type',
    'california_proposition_65_chemical_names1',
    'california_proposition_65_chemical_names2',
    'california_proposition_65_chemical_names3',
    'california_proposition_65_chemical_names4',
    'california_proposition_65_chemical_names5',
    'list_price',
    'product_tax_code',
    'fulfillment_latency',
    'product_site_launch_date',
    'merchant_release_date',
    'restock_date',
    'sale_price',
    'sale_from_date',
    'sale_end_date',
    'offering_end_date',
    'max_aggregate_ship_quantity',
    'item_package_quantity',
    'number_of_items',
    'offering_can_be_gift_messaged',
    'offering_can_be_giftwrapped',
    'is_discontinued_by_manufacturer',
    'max_order_quantity',
    'merchant_shipping_group_name',
    'offering_start_date',
    'bottom_style',
    'collar_style',
    'control_type',
    'pattern_type',
    'pocket_description',
    'special_size_type'
  ];
  $writer->writeSheetRow('Sheet1', $sheetHeader1);
  $writer->writeSheetRow('Sheet1', $sheetHeader2);
  $writer->writeSheetRow('Sheet1', $sheetHeader3);
  while($row=mysqli_fetch_array($result)){
    $key1="";
	$key2="";
	$key3="";
	$key4="";
	$key5="";
	$img1="";
	$img2="";
	$img3="";
	$img4="";
	$img5="";
	$img6="";
	$img7="";
	$img8="";
	$img9="";
	if(!empty($row[keywords])){
	$key=explode("\r\n",$row[keywords]);
	if(!empty($key[0])){$key1=$key[0];}
	if(!empty($key[1])){$key2=$key[1];}
	if(!empty($key[2])){$key3=$key[2];}
	if(!empty($key[3])){$key4=$key[3];}
	if(!empty($key[4])){$key5=$key[4];}
	}
	
	$sqla="select * from ph_img where id in(select imgid from(select imgid from ph_proimg where proid='".$row["ID"]."' and btid is null order by px,id asc) t order by px,id asc)";
	$resulta=mysqli_query($conn,$sqla);
	while($rowa=mysqli_fetch_array($resulta)){
	if(!empty($rowa["imgpath"])){$img1="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img1="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img2="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img2="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img3="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img3="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img4="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img4="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img5="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img5="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img6="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img6="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img7="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img7="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img8="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img8="";}
	$rowa=mysqli_fetch_array($resulta);
	if(!empty($rowa["imgpath"])){$img9="http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"];}else{$img9="";}
	}
	$rowa=null;
	unset($rowa);
    $spliter="<br/>";
	$content=str_replace("\r\n",$spliter,$row["content"]);
    $content=htmlentities($content);
	$sqls="select * from ph_shuxing where proid='".$row["ID"]."' order by ID asc";
  $results=mysqli_query($conn,$sqls);
  $sku=$row["skucode"];
  $content=replacebd($content,$brand);
  if(strpos($row["sketch"], $spliter)==false){
    $des=explode($spliter,$content);
  }else{
    $des=explode("<br/>",$row["sketch"]);
  }
	$des1=$des[0];
	$des2=$des[1];
	$des3=$des[2];
	$des4=$des[3];
	$des5=$des[4];
    $des6=$des[5];
	if(empty($row["kucun"])){$kucun='5';}else{$kucun=$row["kucun"];}
  //if(mysqli_num_rows($results)<1){$upc="UPC";$sku=$row[skucode];$parent="";}else{$upc="";$sku="";$parent="parent";}
  $tbody=[
    $ProductType,
    $sku,
    $brand,
    $row["proname"],
    '',
    '',
    $item_type,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    $department_name,
    '',
    $row["saleprice"],
    //$row["kucun"],
    
	$kucun,
    $img1,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    $img2,
    $img3,
    $img4,
    'parent',
    '',
    '',
    $row["btname"],
    'update',
    $content,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    $des1,
    $des2,
    $des3,
    $des4,
    $des5,
    $des6,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '10',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    ''
   ]; 
   $writer->writeSheetRow('Sheet1', $tbody);
   
  if(mysqli_num_rows($results)<1){
  if(empty($row["kucun"])){$kucun='5';}else{$kucun=$row["kucun"];}
  if($_POST["asin"]=='yes'){$theupc=$row["sid"];$upctype="ASIN";}else{$theupc="";$upctype="UPC";}
    $tbody=[
    $ProductType,
    $sku.'-1',
    $brand,
    $row["proname"],
    $theupc,
    $upctype,
    $item_type,
    '',
    '',
    '',
    '',
    '',
    'color',
    'color',
    'One size',
    $department_name,
    'One size',
    $row["saleprice"],
    //$row["kucun"],
    
	$kucun,
    $img1,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    $img2,
    $img3,
    $img4,
    'child',
    $sku,
    'Variation',
    $row["btname"],
    'update',
    $content,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    $des1,
    $des2,
    $des3,
    $des4,
    $des5,
    $des6,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '10',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    ''
  ];
  $writer->writeSheetRow('Sheet1', $tbody);
  }else{
  $i=0;
  while($rows=mysqli_fetch_array($results)){
  if($_POST["asin"]=='yes'){$theupc=$rows["sid"];$upctype="ASIN";}else{$theupc="";$upctype="UPC";}
  $btimg1="";
  $btimg2="";
  $btimg3="";
  $btimg4="";
  $btimg5="";
  $btimg6="";
  $btimg7="";
  $btimg8="";
  $btimg9="";
  $i=$i+1;
  if(strpos($rows["cname"],",")!==false){$cname=explode(",",$rows["cname"]);$cname1=$cname[0];$cname2=$cname[1];}else{$cname1=$rows["cname"];$cname2="";}
  $sqlb="select * from ph_img where id in(select imgid from(select imgid from ph_proimg where btid='".$rows["ID"]."' order by id asc) t order by id asc)";
	$resultb=mysqli_query($conn,$sqlb);
	while($rowb=mysqli_fetch_array($resultb)){

	if(!empty($rowb["imgpath"])){$btimg1="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg1=$img1;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg2="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg2=$img2;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg3="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg3=$img3;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg4="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg4=$img4;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg5="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg5=$img5;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg6="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg6=$img6;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg7="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg7=$img7;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg8="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg8=$img8;}
	$rowb=mysqli_fetch_array($resultb);
	if(!empty($rowb["imgpath"])){$btimg9="http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"];}else{$btimg9=$img9;}
	}
	if(empty($rows["kucun"])){$kucun='5';}else{$kucun=$rows["kucun"];}
  $tbody=[
    $ProductType,
    $sku.'-'.$i,
    $brand,
    $row["proname"].",".$rows["cname"],
    $theupc,
    $upctype,
    $item_type,
    '',
    '',
    '',
    '',
    '',
    $cname1,
    $cname1,
    $cname2,
    $department_name,
    $cname2,
    $rows["saleprice"],
    //$rows["kucun"],
    
	$kucun,
    $btimg1,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    $btimg1,
    $btimg2,
    $btimg3,
    'child',
    $sku,
    'Variation',
    $row["btname"],
    'update',
    $content,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    $des1,
    $des2,
    $des3,
    $des4,
    $des5,
    $des6,
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '10',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    ''
  ];
$writer->writeSheetRow('Sheet1', $tbody);
  }
  }
  }
  
$writer->writeToStdOut();
}
?>
